import { rollup } from "rollup";
import  babel  from "rollup-plugin-babel";
import { uglify } from "rollup-plugin-uglify";
import  rmrf  from "rmrf";
import chalk from "chalk"

rmrf('dist/');

const inputOptions = {
    input: 'src/index.js',
    plugins:[
      babel({
        exclude: 'node_modules/**'
      }),
      uglify()
    ]
  };

  const outputOptions = {
    file: 'dist/mydb.js',
    format: 'umd',
    name: 'mydb'
  };

  async function build() {
    // create a bundle Rollup对象将构建模块图并执行除屑优化，但不会生成任何输出
    const bundle = await rollup(inputOptions);
  
    // generate code and a sourcemap  使用不同的输出选项对象来生成不同的产物到内存中
    const { code, map } = await bundle.generate(outputOptions);
  
    // or write the bundle to disk  写入磁盘
    await bundle.write(outputOptions);
  }
  
  build().then( () =>{
    console.log(chalk.green('打包完成'))
  })